package com.ufo.store.management.ui.fragment;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ufo.store.management.BarApplication;
import com.ufo.store.management.R;
import com.ufo.store.management.database.DatabaseManager;
import com.ufo.store.management.entity.Isszmbalv3BranchInfo;
import com.ufo.store.management.entity.Isszmbalv3SupcustInfo;
import com.ufo.store.management.entity.SerializableList;
import com.ufo.store.management.entity.SerializableMap;
import com.ufo.store.management.ui.activity.Isszmbalv3MemberActivity;
import com.ufo.store.management.ui.activity.Isszmbalv3PayMasterActivity;
import com.ufo.store.management.ui.activity.Isszmbalv3StockActivity;
import com.ufo.store.management.ui.activity.Isszmbalv3StockEditActivity;
import com.ufo.store.management.ui.activity.SearchIsszmbalv3StockActivity;
import com.ufo.store.management.ui.activity.SettingActivity;
import com.ufo.store.management.utils.ScreenUtil;
import com.ufo.store.management.utils.StatusBarUtil;
import com.ufo.store.management.utils.Utils;
import com.ufo.store.management.widget.view.AutoVerticalScrollTextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Created by taoli on 2016/5/12.
 */
public class HomeFragment extends BaseLazyFragment {
    private AppBarLayout appBarLayout;
    private Toolbar toolBar;
    private CollapsingToolbarLayout coordinatorLayout;
    private View mEntryView;

    private AdvertisementFragment mAdvertisementFragment;
    private HomeControllerFragment mHomeControllerFragment;

    private AutoVerticalScrollTextView mAutoVerticalScrollNewsTv = null;
    private LinearLayout mNewsLl;
    private RelativeLayout expanded_search_rl;
    private TextView expanded_search_tv;
    private ImageView code_iv;
    private RelativeLayout home_controller_rl;
    private ViewPager mCashViewPager;
    public List<Fragment> fragments = new ArrayList<>();

    private HomeShowFragment mHomeShowFragment;

    private MainViewPagerCashAdapter mainViewPagerCashAdapter;

    private SerializableMap mStockTypeMap = new SerializableMap();
    private SerializableMap mIsszmbalv3StockTypeMap = new SerializableMap();
    private SerializableList mIsszmbalv3BranchInfoList = new SerializableList();
    private SerializableList mIsszmbalv3SupcustInfoList = new SerializableList();
    private boolean isApplyLightBarStyle = false;

    private ImageView iv_bg;

    /**
     * 布局文件ID
     *
     * @return
     */
    protected int getLayoutId() {
        return R.layout.fragment_home;
    }

    /**
     * 初始化组件
     */
    protected void initViewData(View entryView) {
        mEntryView = entryView;
        mAutoVerticalScrollNewsTv = (AutoVerticalScrollTextView) entryView.findViewById(R.id.news_tv);
        mNewsLl = (LinearLayout) entryView.findViewById(R.id.news_ll);
        expanded_search_tv = (TextView) entryView.findViewById(R.id.expanded_search_tv);
        expanded_search_rl = (RelativeLayout) entryView.findViewById(R.id.expanded_search_rl);
        coordinatorLayout = (CollapsingToolbarLayout) entryView.findViewById(R.id.toolbar_layout);
        code_iv = (ImageView)entryView.findViewById(R.id.code_iv) ;
        home_controller_rl = (RelativeLayout) entryView.findViewById(R.id.home_controller_rl);

        toolBar = (Toolbar) entryView.findViewById(R.id.toolbar);
        appBarLayout = (AppBarLayout) entryView.findViewById(R.id.appBarLayout);
        appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener);

        mAdvertisementFragment = (AdvertisementFragment) getChildFragmentManager().findFragmentById(R.id.fragment_advertisement_content);
        mHomeControllerFragment = (HomeControllerFragment) getChildFragmentManager().findFragmentById(R.id.fragment_home_controller_content);
        mHomeControllerFragment.setOnClickListener(new HomeControllerFragment.OnClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                if ( mListener != null) {
                    mListener.onItemClick(position);
                }
                if( position == 0 ){
                    Intent toIntent4 = new Intent(getActivity(), Isszmbalv3StockActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("Isszmbalv3StockType", mIsszmbalv3StockTypeMap);
                    bundle.putSerializable("Isszmbalv3SupcustInfo", mIsszmbalv3SupcustInfoList);
                    toIntent4.putExtras(bundle);
                    //startActivity(toIntent4);

                    /**
                     * Now create an {@link android.app.ActivityOptions} instance using the
                     * {@link ActivityOptionsCompat#makeSceneTransitionAnimation(Activity, Pair[])} factory
                     * method.
                     */
                    Pair<View, String> pContent = Pair.create(v.findViewById(R.id.stock_tv), Isszmbalv3StockEditActivity.VIEW_NAME_HEADER_TITLE);
                    Pair<View, String> pImage = Pair.create((View)expanded_search_rl, Isszmbalv3StockEditActivity.VIEW_NAME_HEADER_IMAGE);
                    @SuppressWarnings("unchecked")
                    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                            getActivity(),
                            // Now we provide a list of Pair items which contain the view we can transitioning
                            // from, and the name of the view it is transitioning to, in the launched activity
                            pImage,pContent);
                    // Now we can start the Activity, providing the activity options as a bundle
                    startActivity(toIntent4, activityOptions.toBundle());
                }
                if(position == 1){
                    Intent toIntent2 = new Intent(getActivity(), Isszmbalv3MemberActivity.class);
                    Bundle bundle2 = new Bundle();
                    toIntent2.putExtras(bundle2);
                    //startActivity(toIntent2);
                    /**
                     * Now create an {@link android.app.ActivityOptions} instance using the
                     * {@link ActivityOptionsCompat#makeSceneTransitionAnimation(Activity, Pair[])} factory
                     * method.
                     */
                    Pair<View, String> pContent = Pair.create(v.findViewById(R.id.member_tv), Isszmbalv3StockEditActivity.VIEW_NAME_HEADER_TITLE);
                    Pair<View, String> pImage = Pair.create((View)expanded_search_rl, Isszmbalv3StockEditActivity.VIEW_NAME_HEADER_IMAGE);
                    @SuppressWarnings("unchecked")
                    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                            getActivity(),
                            // Now we provide a list of Pair items which contain the view we can transitioning
                            // from, and the name of the view it is transitioning to, in the launched activity
                            pImage,pContent);
                    // Now we can start the Activity, providing the activity options as a bundle
                    startActivity(toIntent2, activityOptions.toBundle());
                }
                if(position == 2){
                    v.findViewById(R.id.isszmbalv3_bill_iv).setVisibility(View.GONE);
                    Intent toIntent5 = new Intent(getActivity(), Isszmbalv3PayMasterActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("Isszmbalv3BranchInfoList", mIsszmbalv3BranchInfoList);
                    toIntent5.putExtras(bundle);
                    //startActivity(toIntent5);
                    ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(
                            getActivity(),
                            // Now we provide a list of Pair items which contain the view we can transitioning
                            // from, and the name of the view it is transitioning to, in the launched activity
                            v.findViewById(R.id.bill_iv), Isszmbalv3StockActivity.VIEW_NAME_HEADER_IMAGE);
                    // Now we can start the Activity, providing the activity options as a bundle
                    startActivity(toIntent5, activityOptions.toBundle());
                }
                if( position == 3 ){
                    showMonitorController();
                }
            }
        });

        iv_bg = (ImageView) entryView.findViewById(R.id.iv_bg);

        mHomeShowFragment = new HomeShowFragment();
        mHomeShowFragment.setFlurListener(new HomeShowFragment.OnFlurListener(){
            @Override
            public void onFlurChanged(Bitmap bg){
                iv_bg.setImageBitmap(bg);
            }
        });

        fragments.add(mHomeShowFragment);

        mainViewPagerCashAdapter = new MainViewPagerCashAdapter(getActivity(), getFragmentManager());
        mCashViewPager = (ViewPager) entryView.findViewById(R.id.viewPager);
        mCashViewPager.setAdapter(mainViewPagerCashAdapter);

        mNewsLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toIntent = new Intent(getActivity(), SettingActivity.class);
                startActivity(toIntent);
            }
        });
        expanded_search_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startIsszmbalv3SearchActivity();
            }
        });
        code_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
    }

    /**
     * 初始化数据
     */
    protected void initData() {
        loaded();
    }

    protected void onFirstUserVisible() {
        if (isApplyLightBarStyle) {
            StatusBarUtil.StatusBarLightMode(getActivity(), R.color.transparent, false);
        } else {
            StatusBarUtil.setStatusBarColor(getActivity(), R.color.transparent, false);
        }
        getAutoVerticalScrollInfomation();
        getAdvertisement();
        getStockTypeInfoList();
    }

    protected void onUserVisible() {
        if (isApplyLightBarStyle) {
            StatusBarUtil.StatusBarLightMode(getActivity(), R.color.transparent, false);
        } else {
            StatusBarUtil.setStatusBarColor(getActivity(), R.color.transparent, false);
        }

        if( mHomeShowFragment != null ){
            mHomeShowFragment.startAnimateRolling();
            mHomeShowFragment.startAnimateExhibit();
        }
    }

    protected void onFirstUserInvisible() {
        if( mHomeShowFragment != null ){
            mHomeShowFragment.pauseAnimateRolling();
            mHomeShowFragment.pauseAnimateExhibit();
        }
    }

    protected void onUserInvisible() {
        if( mHomeShowFragment != null ){
            mHomeShowFragment.pauseAnimateRolling();
            mHomeShowFragment.pauseAnimateExhibit();
        }
    }

    private void startIsszmbalv3SearchActivity() {
        if (mIsszmbalv3StockTypeMap != null && mIsszmbalv3StockTypeMap.getMap() != null && mIsszmbalv3StockTypeMap.getMap().size() > 1) {
            Intent toIntent = new Intent(getActivity(), SearchIsszmbalv3StockActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("Isszmbalv3StockType", mIsszmbalv3StockTypeMap);
            bundle.putSerializable("Isszmbalv3SupcustInfo", mIsszmbalv3SupcustInfoList);
            bundle.putInt("SearchMode", SearchIsszmbalv3StockActivity.SEARCH_BY_STOCKSPELL);
            toIntent.putExtras(bundle);
            //startActivity(toIntent);
            @SuppressWarnings("unchecked")
            ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(
                    getActivity(),
                    // Now we provide a list of Pair items which contain the view we can transitioning
                    // from, and the name of the view it is transitioning to, in the launched activity
                    mEntryView.findViewById(R.id.expanded_search_tv), "searchbar");
            startActivity(toIntent, activityOptions.toBundle());
        } else {
            Toast.makeText(getActivity(), "尚未连接到数据库，请检查连接", Toast.LENGTH_SHORT).show();
        }
    }

    private int homeControllerHeight = 0;
    private void showMonitorController(){
        ValueAnimator va = null;
        if( homeControllerHeight == 0 ) {        //动画展开
            homeControllerHeight = home_controller_rl.getMeasuredHeight();
            int endHeight = homeControllerHeight * 2;
            va = ValueAnimator.ofInt(homeControllerHeight, endHeight);
        }else{                                  //动画收缩
            homeControllerHeight = home_controller_rl.getMeasuredHeight();
            int endHeight = (int) Utils.dp2px(getResources(), 110);
            va = ValueAnimator.ofInt(homeControllerHeight, endHeight);
            homeControllerHeight = 0;
        }

        final RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) home_controller_rl.getLayoutParams();
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int h = (int) animation.getAnimatedValue();
                relativeParams.height = h;
                home_controller_rl.setLayoutParams(relativeParams);
                home_controller_rl.requestLayout();
            }
        });
        va.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                if( homeControllerHeight == 0 )
                    mHomeShowFragment.setScrollYMaxHeight(110);            //收缩后控制栏的高度
                else
                    mHomeShowFragment.setScrollYMaxHeight(220);            //展开后控制栏的高度
            }

            @Override
            public void onAnimationEnd(Animator animation) {

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        va.setInterpolator(new OvershootInterpolator());
        va.setDuration(450);
        va.start();
    }

    /**
     * @desc
     * @author taoli
     * @time 2017/10/10 0010
     * 0:EXPANDED(展开)   1:COLLAPSED(折叠)   2:INTERNEDIATE(中间)
     */
    private int state = 0;
    private AppBarLayout.OnOffsetChangedListener onOffsetChangedListener = new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            mNewsLl.setTranslationX(Math.abs(verticalOffset)* ScreenUtil.getScreenSize(getActivity())[0]/appBarLayout.getTotalScrollRange());
            //verticalOffset>=0  Toolbar全部显示
            if (verticalOffset == 0) {
                //修改状态标记为展开
                if (state != 0) {
                    state = 0;
                    isApplyLightBarStyle = false;
                    mHomeShowFragment.setPullRefresh(true);
                    //coordinatorLayout.setTitle("EXPANDED");
                   // expandedCollapsingToolbarLayout(true);
                    expanded_search_rl.setBackgroundResource(R.drawable.shape_search_bg);
                    StatusBarUtil.setStatusBarColor(getActivity(), R.color.transparent, false);
                }
            } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                //修改状态标记为折叠
                if (state != 1) {
                    state = 1;
                    isApplyLightBarStyle = true;
                    mHomeShowFragment.setPullRefresh(false);
                    //coordinatorLayout.setTitle("COLLAPSED");
                   // expandedCollapsingToolbarLayout(false);
                    expanded_search_rl.setBackgroundResource(R.drawable.shape_search_black_bg);
                    StatusBarUtil.StatusBarLightMode(getActivity(), R.color.transparent, false);
                }
            } else {
                //修改状态标记为中间
                if (state != 2) {
                    state = 2;
                    mHomeShowFragment.setPullRefresh(false);
                    //coordinatorLayout.setTitle("INTERNEDIATE");
                }
            }
        }
    };

    /**
     * @desc 按照ActionBar的伸缩状态动态变化搜索框样式
     * @author taoli
     * @time 2017/10/10 0010
     */
    private void expandedCollapsingToolbarLayout(boolean isExpanded) {
        if (isExpanded) {
            List<Animator> titleAnimators = new ArrayList<>();
            ObjectAnimator mAnimator = ObjectAnimator.ofFloat(expanded_search_rl, View.ALPHA, 0.0f, 1.0f);
            ObjectAnimator mAnimator0 = ObjectAnimator.ofFloat(expanded_search_rl, View.TRANSLATION_Y, -Utils.dp2px(getResources(),40), 0.0f);
            //ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(collapsed_search_tv, View.ALPHA, 1.0f, 0.0f);
           // ObjectAnimator mAnimator2 = ObjectAnimator.ofFloat(collapsed_search_tv, View.TRANSLATION_Y, 0.0f, Utils.dp2px(getResources(),40));
            ObjectAnimator mAnimator3 = ObjectAnimator.ofFloat(code_iv, View.ALPHA, 1.0f, 0.0f);
            ObjectAnimator mAnimator4 = ObjectAnimator.ofFloat(code_iv, View.TRANSLATION_Y, 0.0f,Utils.dp2px(getResources(),40));
            titleAnimators.add(mAnimator);
            titleAnimators.add(mAnimator0);
           // titleAnimators.add(mAnimator1);
            //titleAnimators.add(mAnimator2);
            titleAnimators.add(mAnimator3);
            titleAnimators.add(mAnimator4);
            AnimatorSet mAnimatorSet = new AnimatorSet();
            mAnimatorSet.setDuration(400);
            mAnimatorSet.playTogether(titleAnimators);
            mAnimatorSet.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    expanded_search_rl.setAlpha(0.0f);
                    expanded_search_rl.setTranslationY(-Utils.dp2px(getResources(),40));
                    expanded_search_rl.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                   // collapsed_search_tv.setVisibility(View.GONE);
                    code_iv.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            mAnimatorSet.start();
        } else {
            List<Animator> titleAnimators = new ArrayList<>();
            ObjectAnimator mAnimator = ObjectAnimator.ofFloat(expanded_search_rl, View.ALPHA, 1.0f, 0.0f);
            ObjectAnimator mAnimator0 = ObjectAnimator.ofFloat(expanded_search_rl, View.TRANSLATION_Y, 0.0f, -Utils.dp2px(getResources(),40));
            //ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(collapsed_search_tv, View.ALPHA, 0.0f, 1.0f);
           // ObjectAnimator mAnimator2 = ObjectAnimator.ofFloat(collapsed_search_tv, View.TRANSLATION_Y, Utils.dp2px(getResources(),40), 0.0f);
            ObjectAnimator mAnimator3 = ObjectAnimator.ofFloat(code_iv, View.ALPHA, 0.0f, 1.0f);
            ObjectAnimator mAnimator4 = ObjectAnimator.ofFloat(code_iv, View.TRANSLATION_Y, Utils.dp2px(getResources(),40), 0.0f);
            titleAnimators.add(mAnimator);
            titleAnimators.add(mAnimator0);
            //titleAnimators.add(mAnimator1);
           // titleAnimators.add(mAnimator2);
            titleAnimators.add(mAnimator3);
            titleAnimators.add(mAnimator4);
            AnimatorSet mAnimatorSet = new AnimatorSet();
            mAnimatorSet.playTogether(titleAnimators);
            mAnimatorSet.setDuration(400);
            mAnimatorSet.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                  //  collapsed_search_tv.setTranslationY(-Utils.dp2px(getResources(),40));
                  //  collapsed_search_tv.setAlpha(0.0f);
                  //  collapsed_search_tv.setVisibility(View.VISIBLE);
                    code_iv.setTranslationY(-Utils.dp2px(getResources(),40));
                    code_iv.setAlpha(0.0f);
                    code_iv.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    expanded_search_rl.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            mAnimatorSet.start();
        }
    }

    /**
     * @desc 获取滚动信息
     * @author taoli
     * @time 2017/8/11 0011
     */
    private String[] strings = {"全新的界面和系统架构", "轻松部署千家连锁", "特色批次管理","精准行业分级销售","支持各种电子秤","兼容性强、收银效率高"};
    private int number = 0;
    private CountDownTimer jiceTimer;

    private void getAutoVerticalScrollInfomation() {
        mAutoVerticalScrollNewsTv.setText(strings[0]);
        if (jiceTimer == null) {
            jiceTimer = new CountDownTimer(Long.MAX_VALUE, 6000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    mAutoVerticalScrollNewsTv.next();
                    number++;
                    mAutoVerticalScrollNewsTv.setText(strings[number % strings.length]);
                }

                @Override
                public void onFinish() {

                }
            };
            jiceTimer.start();
        } else {
            jiceTimer.cancel();
            jiceTimer.start();
        }
    }

    /**
     * @desc 获取广告
     * @author taoli
     * @time 2017/8/22 0022
     */
    private void getAdvertisement() {
        ArrayList<View> viewList = new ArrayList<View>();
        ImageView view1 = new ImageView(getActivity());
        view1.setImageResource(R.drawable.ad0);
        view1.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view1.setTag(0);
        viewList.add(view1);
        ImageView view2 = new ImageView(getActivity());
        view2.setImageResource(R.drawable.ad1);
        view2.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view2.setTag(1);
        viewList.add(view2);
        ImageView view3 = new ImageView(getActivity());
        view3.setImageResource(R.drawable.ad2);
        view3.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view3.setTag(2);
        viewList.add(view3);
        ArrayList<String> viewListTitles = new ArrayList<String>();
        viewListTitles.add("昊聚精品，口口美味");
        mAdvertisementFragment.setData(viewList, viewListTitles);
    }

    /**
     * @desc 获取商品信息
     * @author taoli
     * @time 2017/8/22 0022
     */
    private synchronized void getStockTypeInfoList() {
        if (getActivity().isFinishing()) {
            return;
        }
        new GetStockTypeInfoListTask().execute();
    }

    private class GetStockTypeInfoListTask extends AsyncTask<Void, Void, String> {
        public GetStockTypeInfoListTask() {

        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(Void... params) {
            if (getActivity().isFinishing()) {
                return null;
            }
            if (BarApplication.getInstance().mDatabaseIsSqlServer) {
                //获取商品分类信息
                Map<String, String> isszmbalv3StockTypeMap = DatabaseManager.getIsszmbalv3StockTypeListFromSqlServer(getActivity());
                mIsszmbalv3StockTypeMap.setMap(isszmbalv3StockTypeMap);
                //获取门店信息
                List<Isszmbalv3BranchInfo> isszmbalv3BranchInfoList = DatabaseManager.getIsszmbalv3BranchInfoListFromSqlServer(getActivity());
                mIsszmbalv3BranchInfoList.setIsszmbalv3BranchInfoList(isszmbalv3BranchInfoList);
                //获取供应商信息
                //List<Isszmbalv3SupcustInfo> isszmbalv3SupcustInfoList = DatabaseManager.getIsszmbalv3SupcustInfoListFromSqlServer(getActivity());
                //mIsszmbalv3SupcustInfoList.setIsszmbalv3SupcustInfoList(isszmbalv3SupcustInfoList);
            } else {
                //获取商品分类信息
                Map<String, String> isszmbalv3StockTypeMap = DatabaseManager.getIsszmbalv3StockTypeListFromLocal(getActivity());
                mIsszmbalv3StockTypeMap.setMap(isszmbalv3StockTypeMap);
                //获取门店信息
                List<Isszmbalv3BranchInfo> isszmbalv3BranchInfoList = DatabaseManager.getIsszmbalv3BranchInfoListFromLocal(getActivity());
                mIsszmbalv3BranchInfoList.setIsszmbalv3BranchInfoList(isszmbalv3BranchInfoList);
                //获取供应商信息
                //List<Isszmbalv3SupcustInfo> isszmbalv3SupcustInfoList = DatabaseManager.getIsszmbalv3SupcustInfoListFromLocal(getActivity());
                //mIsszmbalv3SupcustInfoList.setIsszmbalv3SupcustInfoList(isszmbalv3SupcustInfoList);
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (getActivity().isFinishing()) {
                return;
            }
//            if (mStockTypeMap != null && mStockTypeMap.getMap() != null && mStockTypeMap.getMap().size() > 1) {
//                mHomeControllerFragment.setStockTypeMap(mStockTypeMap);
//            }
            if (mIsszmbalv3StockTypeMap != null && mIsszmbalv3StockTypeMap.getMap() != null && mIsszmbalv3StockTypeMap.getMap().size() > 1) {
                mHomeShowFragment.setIsszmbalv3StockTypeMap(mIsszmbalv3StockTypeMap);
                mHomeControllerFragment.setIsszmbalv3StockTypeMap( mIsszmbalv3StockTypeMap);
            }
            if( mIsszmbalv3BranchInfoList != null && mIsszmbalv3BranchInfoList.getIsszmbalv3BranchInfoList() != null && mIsszmbalv3BranchInfoList.getIsszmbalv3BranchInfoList().size() > 0 ){
                mHomeShowFragment.setIsszmbalv3BranchInfoList(mIsszmbalv3BranchInfoList);
                mHomeControllerFragment.setIsszmbalv3BranchInfoList(mIsszmbalv3BranchInfoList);
            }
           // if( mIsszmbalv3SupcustInfoList != null && mIsszmbalv3SupcustInfoList.getIsszmbalv3SupcustInfoList() != null && mIsszmbalv3SupcustInfoList.getIsszmbalv3SupcustInfoList().size() > 0 ){
            //    mHomeShowFragment.setIsszmbalv3SupcustInfoList(mIsszmbalv3SupcustInfoList);
           //     mHomeControllerFragment.setIsszmbalv3SupcustInfoList(mIsszmbalv3SupcustInfoList);
            //}
        }
    }

    /**
     * 首页商品/会员适配器
     * 2016/02/26
     */
    public class MainViewPagerCashAdapter extends FragmentStatePagerAdapter {
        private List<String> data = new ArrayList<>();

        public MainViewPagerCashAdapter(Context context, FragmentManager fm) {
            super(fm);
            data.add("历史纪录");
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return data.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return data.size();
        }
    }

    private OnClickListener mListener;

    public void setOnClickListener(OnClickListener l) {
        mListener = l;
    }

    public interface OnClickListener {
        void onItemClick(int position);
        void onDrawerClick();
    }
}

